package com.hjm.admin.moule.widget;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by admin on 2017/9/28.
 */

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    int left, right, top, bottom;
    private boolean isVertical;

    public SpacesItemDecoration(int space) {
        this.left = space;
        this.right = space;
        this.top = space;
        this.bottom = space;
        isVertical = false;
    }

    public SpacesItemDecoration(int left, int right, int top, int bottom) {
        this.left = left;
        this.right = right;
        this.top = top;
        this.bottom = bottom;
        isVertical = false;
    }

    public SpacesItemDecoration(int space, boolean vertival) {
        this.left = space;
        this.right = space;
        this.top = space;
        this.bottom = space;
        this.isVertical = vertival;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.left = left;
        outRect.right = right;
        outRect.bottom = bottom;
        if (isVertical) {
            if (parent.getChildAdapterPosition(view) == 0) {
                outRect.top = top;
            }
        }
    }
}
